﻿using System.Web;
using CKFinder;
using CKFinder.Connector;

namespace CKFinderImageCroppingPlugin.Plugin
{
	public class ImageCropperPlugin : CKFinderPlugin
	{
		public void Init(CKFinderEvent ckFinderEvent)
		{
			ckFinderEvent.BeforeExecuteCommand += ImageCropperBeforeExecuteCommandHandler;
		}

		public string JavascriptPlugins
		{
			get { return "ImageCropper"; }
		}

		protected void ImageCropperBeforeExecuteCommandHandler(object sender, CKFinderEventArgs e)
		{
			var command = (string) e.data[0];

			if (command == "ImageCropper")
			{
				var commandHandler = new ImageCropperCommandHandler();
				var response = (HttpResponse) e.data[1];
				commandHandler.SendResponse(response);
			}
		}
	}
}